//
//  ZYCDutyRecordTipView.m
//  ZDSC
//
//  Created by ZDTX on 2021/8/19.
//

#import "ZYCDutyRecordTipView.h"
@interface ZYCDutyRecordTipView ()
@property (nonatomic, strong) UIView *dimView;
@property (nonatomic, strong) UIImageView *iconImageView;
@property (nonatomic, strong) UIView *baseView;
@property (nonatomic, strong) UILabel *tipLabel;
@property (nonatomic, strong) UILabel *contentLabel;

@property (nonatomic, strong) UIButton *comfirmButton;
@end
@implementation ZYCDutyRecordTipView

- (void)setTipString:(NSString *)tipString{
    _tipString = tipString;
    _contentLabel.text = tipString;
}

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight);
        self.hidden = NO;
        self.dimView.hidden = NO;
        self.baseView.hidden = NO;
        [self addSubview:self.dimView];
        [self addSubview:self.baseView];
        [self addSubview:self.iconImageView];

        [self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.baseView.mas_centerX).offset(-10.0f);
            make.centerY.equalTo(self.baseView.mas_top);
            make.size.mas_equalTo(CGSizeMake(83, 70));
        }];
        
        [self setupUI];
    }
    return self;
}

- (void)setupUI{

    [self.baseView addSubview:self.tipLabel];
    [self.baseView addSubview:self.contentLabel];
    [self.baseView addSubview:self.comfirmButton];
    
    
    [self.tipLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.baseView).offset(12.0f);
        make.centerX.equalTo(self.baseView.mas_centerX).offset(10.0f);
    }];
    
    [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.baseView).offset(65.0f);
        make.centerX.equalTo(self.baseView);
    }];
    
    [self.comfirmButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentLabel.mas_bottom).offset(35.0f);
        make.centerX.equalTo(self.baseView);
        make.size.mas_equalTo(CGSizeMake(120, 40));
    }];
    
}
- (UIView *)dimView{
    if (!_dimView) {
        _dimView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
        _dimView.alpha = 0.7;
        _dimView.backgroundColor = [UIColor blackColor];

    }
    return _dimView;
}

- (UIView *)baseView{
    if (!_baseView) {
        _baseView = [[UIView alloc] initWithFrame:CGRectMake(24, 270, kScreenWidth-2*24, 200)];
        _baseView.alpha = 1.0f;
        _baseView.layer.cornerRadius = 7.5f;
        _baseView.layer.masksToBounds = YES;
        _baseView.backgroundColor = [UIColor whiteColor];

    }
    return _baseView;
}


- (UILabel *)tipLabel {
    if (!_tipLabel) {
        _tipLabel = [UILabel LabelWithString:@"提醒" Font:kSystemBoldFont(17.0f) titleColor:HEX_RGB(@"#2B302D") textAlignment:ZZTextAlignmentCenter];
    }
    return _tipLabel;
}

- (UILabel *)contentLabel {
    if (!_contentLabel) {
        _contentLabel = [UILabel LabelWithFont:kCustomFont(@"PingFangSC-Light", 17.0f) titleColor:HEX_RGB(@"#888888") textAlignment:ZZTextAlignmentCenter];

        _contentLabel.numberOfLines = 0;
    }
    return _contentLabel;
}

- (UIImageView *)iconImageView {
    if (!_iconImageView) {
        _iconImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"yx"]];
    }
    return _iconImageView;
}

- (UIButton *)comfirmButton {
    if (!_comfirmButton) {
        _comfirmButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _comfirmButton.frame = CGRectMake(0,0, 120, 40);
        [_comfirmButton setTitle:@"确定" forState:UIControlStateNormal];
        [_comfirmButton setTitleColor:HEX_RGB(kTitleWhiteColor) forState:UIControlStateNormal];
//        _comfirmButton.backgroundColor = HEX_RGB(@"#009B4C");
        _comfirmButton.titleLabel.font = kCustomFont(@"PingFangSC-Light", 17.0f);
        [_comfirmButton addTarget:self action:@selector(clickComfimAction:) forControlEvents:UIControlEventTouchUpInside];
        _comfirmButton.layer.cornerRadius = 20;
        _comfirmButton.layer.masksToBounds = YES;
        CAGradientLayer *gradientLayer = [CAGradientLayer layer];
        gradientLayer.startPoint = CGPointMake(0, 0);
        gradientLayer.endPoint = CGPointMake(1, 0);
        gradientLayer.colors = @[(__bridge id)HEX_RGB(@"#009B4C").CGColor,
                                 (__bridge id)HEX_RGB(@"#F6EEB0").CGColor];
        gradientLayer.locations = @[@(0.3),@(1.0f)];
        gradientLayer.frame = _comfirmButton.bounds;
        gradientLayer.cornerRadius = 24;
        [_comfirmButton.layer insertSublayer:gradientLayer atIndex:0];
    }
    return _comfirmButton;
}

- (void)clickComfimAction:(UIButton *)sender{
    [self dismiss];
}


- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{


    [self dismiss];
}
- (void)dismiss{
    self.hidden = YES;
    self.dimView.hidden = YES;
    self.baseView.hidden = YES;
//    [UIView animateWithDuration:0.3f animations:^{
//        self.baseView.frame = CGRectMake(0, kScreenHeight, kScreenWidth, kWidth(240));
//    }completion:^(BOOL finished) {
//        self.hidden = YES;
//        self.dimView.hidden = YES;
//        self.baseView.hidden = YES;
//    }];
}

- (void)show{
    self.hidden = NO;
    self.dimView.hidden = NO;
    self.baseView.hidden = NO;
    [UIView animateWithDuration:0.3f animations:^{
        self.baseView.frame = CGRectMake(24, 270, kScreenWidth-2*24, 200);
    }];

}
@end
